package com.topisv.tms.web.work;

import java.io.PrintWriter;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.topisv.tms.service.account.ShiroDbRealm.ShiroUser;
import com.topisv.tms.service.work.WorkOrderService;

/**
 * 订单
 * @author ch
 *
 */
@Controller
@RequestMapping(value = "/workOrder")
public class WorkOrderController {

	private static final Logger logger = LoggerFactory.getLogger(WorkOrderController.class);
	@Autowired
	private WorkOrderService workOrderService;

	/**
	 * 取消订单
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "ajaxCancelOrder")
	public void ajaxCancelOrder(ServletRequest request,HttpServletResponse response) {
		
		PrintWriter out=null;
		JSONObject json=null;
		String msg=null;
		
		try {	
			
			out = response.getWriter();
			json = new JSONObject();
			
			ShiroUser curUser = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
			
			String orderno=request.getParameter("orderno"); 
		    msg=this.workOrderService.cancelOrder(orderno,curUser.jobuuid);
			
		    json.put("msg", msg);
			out.print(json);
			
		} catch (Exception e) {
			
			logger.error("error",e);
			json.put("msg", "error");
			out.print(json);
		}
	}
	
	
}
